package com.Xht.www.dao;

import com.Xht.www.po.SalesVolumeInfoPO;
import java.sql.*;

public class SalesVolumeInfoDAO extends BaseDAO {

    // 更新销量
    public void updateTotalSalesVolume(Connection connection, String merchantName, int totalSales) throws SQLException {
        String sql = "UPDATE sales_volume_info SET quantity_sold = ? " +
                "WHERE merchant_name = ?";

        try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
            pstmt.setInt(1, totalSales);
            pstmt.setString(2, merchantName);
            pstmt.executeUpdate();
        }
    }

    // 插入销量记录
    public void insertSalesRecord(Connection connection, SalesVolumeInfoPO record) throws SQLException {
        String sql = "INSERT INTO sales_volume_info (merchant_name, quantity_sold) " +
                "VALUES (?, ?)";

        try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
            pstmt.setString(1, record.getMerchantName());
            pstmt.setInt(2, record.getQuantitySold());
            pstmt.executeUpdate();
        }
    }

}